package study.cell_game.objects.tokens;

import org.andengine.entity.sprite.Sprite;

import study.cell_game.activity.GameActivity;
import study.cell_game.enums.BorderType;
import study.cell_game.enums.TokenType;
import study.cell_game.objects.borders.Border;
import study.cell_game.objects.borders.BorderFactory;
import study.cell_game.objects.textures.TokenTextures;

public class TokenFactory {

	public static Token createProc1(BorderType borderType, int X, int Y) {

		Border border = null;
		switch (borderType) {
		case STRAIGHT_IN_OUT:
			border = BorderFactory.createStraightInOutBorder(0,0);
			break;
		case TRIANGLE_IN_TRIANGLE_OUT:
			border = BorderFactory.createTriangularInTriangularOutBorder(0,0);
			break;
		case TRIANGLE_IN_OUT:
			border = BorderFactory.createTriangularInOutBorder(0,0);
			break;
		default:
			break;
		}
		
		Sprite core = new Sprite(X, Y, TokenTextures.getInstance().getProc1(),
				GameActivity.main.getVertexBufferObjectManager());
		
		core.attachChild(border.getActiveSprite());

		ProcesorLogic logic = new ProcesorLogic(TokenType.PROC1);
		
		Token result = new Token(core, border, 0, 10, 10, logic, id++, false);
		
		logic.setParent(result);
		
		return result;
	}

	public static Token createProc2(BorderType borderType, int X, int Y) {
		Border border = null;
		switch (borderType) {
		case STRAIGHT_IN_OUT:
			border = BorderFactory.createStraightInOutBorder(0,0);
			break;
		case TRIANGLE_IN_TRIANGLE_OUT:
			border = BorderFactory.createTriangularInTriangularOutBorder(0,0);
			break;
		case TRIANGLE_IN_OUT:
			border = BorderFactory.createTriangularInOutBorder(0,0);
			break;
		default:
			break;
		}
		
		Sprite core = new Sprite(X, Y, TokenTextures.getInstance().getProc2(),
				GameActivity.main.getVertexBufferObjectManager());
		
		core.attachChild(border.getActiveSprite());
		
		ProcesorLogic logic = new ProcesorLogic(TokenType.PROC2);
		
		Token result = new Token(core, border, 0, 20, 25, logic, id++, false);

		logic.setParent(result);
		
		return result;
	}

	public static Token createProc3(BorderType borderType, int X, int Y) {
		Border border = null;
		switch (borderType) {
		case STRAIGHT_IN_OUT:
			border = BorderFactory.createStraightInOutBorder(0,0);
			break;
		case TRIANGLE_IN_TRIANGLE_OUT:
			border = BorderFactory.createTriangularInTriangularOutBorder(0,0);
			break;
		case TRIANGLE_IN_OUT:
			border = BorderFactory.createTriangularInOutBorder(0,0);
			break;
		default:
			break;
		}
		
		Sprite core = new Sprite(X, Y, TokenTextures.getInstance().getProc3(),
				GameActivity.main.getVertexBufferObjectManager());
		
		core.attachChild(border.getActiveSprite());
		
		ProcesorLogic logic = new ProcesorLogic(TokenType.PROC3);
		
		Token result = new Token(core, border, 1, 30, 40, logic, id++, false);
		
		logic.setParent(result);
		
		return result;
	}

	public static Token createRam1(BorderType borderType, int X, int Y) {
		Border border = null;
		switch (borderType) {
		case STRAIGHT_IN_OUT:
			border = BorderFactory.createStraightInOutBorder(0,0);
			break;
		case TRIANGLE_IN_TRIANGLE_OUT:
			border = BorderFactory.createTriangularInTriangularOutBorder(0,0);
			break;
		case TRIANGLE_IN_OUT:
			border = BorderFactory.createTriangularInOutBorder(0,0);
			break;
		default:
			break;
		}
		
		Sprite core = new Sprite(X, Y, TokenTextures.getInstance().getRam1(),
				GameActivity.main.getVertexBufferObjectManager());
		
		core.attachChild(border.getActiveSprite());
		
		RamLogic logic = new RamLogic();
		
		Token result = new Token(core, border, 1, 20, 80, logic, id++, false);
		
		logic.setParent(result);
		
		return result;
	}
	
	public static Token createRotate(int X, int Y){
		Border border = BorderFactory.createFullBorder(0,0);
		
		
		Sprite core = new Sprite(X, Y, TokenTextures.getInstance().getRotate(),
				GameActivity.main.getVertexBufferObjectManager());
		
		core.attachChild(border.getActiveSprite());

		return new Token(core, border, 0, 0, 0, null, id++, true);
	}
	
	public static Token createOvertake(int X, int Y){
		Border border = BorderFactory.createFullBorder(0,0);
		
		
		Sprite core = new Sprite(X, Y, TokenTextures.getInstance().getOvertake(),
				GameActivity.main.getVertexBufferObjectManager());
		
		core.attachChild(border.getActiveSprite());
		
		return new Token(core, border, 0, 0, 0, null, id++, true);
	}
	
	private static int id = 0;

}
